import request from '@/utils/request'
import { Device } from '@/types/device';
/**
 * 获取所有设备信息
 * @returns 返回设备列表
 */
export function getAllEquipments() {
    return request({
        url: '/admin/getAllEquipments',
        method: 'get',
    });
}

export function getAllWillOverdueEquips() {
    return request({
        url: '/admin/getAllWillOverdueEquips',
        method: 'get',
    });
}

export function getAllOverdueEquips() {
    return request({
        url: '/admin/getAllOverdueEquips',
        method: 'get',
    });
}

export const deleteEquipment = (id: number) => {
    return request.delete('/admin/deleteEquipment', { data: { id } } );
};

// 根据企业名称查找设备
export const getAllEquipmentsByCompanyName = (companyName: string) => {
    return request.get('/admin/getAllEquipmentsByCompanyName', {
        params: { companyName },
    });
};

export const getOverdueEquipmentsByCompanyName = (companyName: string) => {
    return request.get('/admin/getOverdueEquipsByCompanyName', {
        params: { companyName },
    });
};

export const getWillOverdueEquipsByCompanyName = (companyName: string) => {
    return request.get('/admin/getOverdueEquipsByCompanyName', {
        params: { companyName },
    });
};

/**
 * 导出指定单位名称的设备表格
 * @param companyName 单位名称
 * @returns 返回文件下载流
 */
export function exportAllEquipment(companyName: string) {
    return request({
        url: '/admin/exportAllByCompanyName',
        method: 'get',
        params: { companyName },
        responseType: 'blob', // 指定响应类型为二进制文件
    });
}

export function exportAll() {
    return request({
        url: '/admin/exportAll',
        method: 'get',
        responseType: 'blob', // 指定响应类型为二进制文件
    });
}

/**
 * 新增设备
 * @param equipment 设备信息
 * @returns 返回操作结果
 */
export function insertEquip(equipment: Device) {
    return request({
        url: '/user/insertEquip',
        method: 'post',
        data: equipment, // 使用 data 传递请求体
    });
}

/**
 * 更新设备
 * @param equipment 设备信息
 * @returns 返回操作结果
 */
export function updateEquip(equipment: Device) {
    return request({
        url: '/user/updateEquip',
        method: 'post',
        data: equipment, // 使用 data 传递请求体
    });
}